//
//  AppDelegate.m
//  UILesson2_UIButton
//
//  Created by lanou3g on 15/12/15.
//  Copyright © 2015年 郭丹. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[UIViewController alloc] init];
    
    
    //button继承于UIControl,可以相应事件
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = 101;
    
    [button setFrame:CGRectMake(50, 50, 300, 50)];
    
    [button setBackgroundColor:[UIColor cyanColor]];
    
    //[button setTitle:@"iOS" forState:UIControlStateNormal];
    //[button setTitle:@"hl" forState:UIControlStateHighlighted];
    
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    //不显示？？？？？？？
    button.titleLabel.text = @"aaa";
    button.titleLabel.textColor = [UIColor redColor];
    button.titleLabel.frame = CGRectMake(0, 0, 50, 50);
    button.titleLabel.hidden = NO;
    
   // NSLog(@"%p",button.titleLabel.text);
    
    
    //后面的state一定要对应，正常情况下都是normal
    //[button setTitle:@"按过了" forState:UIControlStateHighlighted];
    
    //button.selected = YES;
    
    
    
    //button 的点击响应事件
    //[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    [self.window addSubview:button];
    
    
    return YES;
}

-(void)buttonAction:(UIButton *)sender {
    //1
    //self.window.subviews[1].backgroundColor = [UIColor redColor];
    
    //2
    for (UIView *view in self.window.subviews) {
        if( [view isKindOfClass:[UIButton class]]){
            view.backgroundColor = [UIColor greenColor];
            NSLog(@"2");
        }
    }
    
    //3
//    [self.window viewWithTag:101].backgroundColor = [UIColor redColor];
    
    //4
    //使用属性
    
    //5:传递参数
//    CGFloat number1 = arc4random() % 256;
//    CGFloat number2 = arc4random() % (255 - 0 + 1) + 0;
//    CGFloat number3 = arc4random() % (255 - 0 + 1) + 0;
//    sender.backgroundColor = [UIColor colorWithRed:number1 / 255.0 green:number2 / 255.0 blue:number3 / 255.0 alpha:1];
    
    
//    sender.selected = !sender.selected;
//    [sender setTitle:sender.selected ? @"AAAAAAA" : @"iOS" forState:UIControlStateNormal];
    
//    if (sender.selected) {
//        sender.selected = NO;
//        [sender setTitle:@"AAAAA" forState:UIControlStateNormal];
//    } else {
//        sender.selected = YES;
//        [sender setTitle:@"iOS" forState:UIControlStateNormal];
//    }
    
    
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
